import os
import glob
Import('env')

# Mo Builder

def mobuilder_action(source, target, env, for_signature):
	cmd = 'msgfmt %s -o %s' % (source[0], target[0]);
	return cmd

# Environment

if GetOption ('clean'):
	Execute(Delete('locale'));

moFile = Builder(generator = mobuilder_action);

localeEnv = Environment(BUILDERS = {'Locale' : moFile });

# Build and Install

for po in glob.glob('*.po'):
	lang = po.split('.')[0]
	localeEnv.Locale('locale/%s/LC_MESSAGES/dcsharp.mo' % lang, po);
	
	# Install
	
	localeDir = env['DESTDIR'] + os.sep + os.path.join(env['SHAREDIR'], 'locale/%s/LC_MESSAGES' % lang)
	env.Alias("install", env.InstallData(localeDir, 'locale/%s/LC_MESSAGES/dcsharp.mo' % lang))
